<?php


/**
 * Base class that represents a query for the 'provinces' table.
 *
 *
 *
 * @method ProvincesQuery orderById($order = Criteria::ASC) Order by the id column
 * @method ProvincesQuery orderByGameId($order = Criteria::ASC) Order by the game_id column
 * @method ProvincesQuery orderByPlayerId($order = Criteria::ASC) Order by the player_id column
 * @method ProvincesQuery orderByProvinceDefId($order = Criteria::ASC) Order by the province_def_id column
 * @method ProvincesQuery orderByActive($order = Criteria::ASC) Order by the active column
 *
 * @method ProvincesQuery groupById() Group by the id column
 * @method ProvincesQuery groupByGameId() Group by the game_id column
 * @method ProvincesQuery groupByPlayerId() Group by the player_id column
 * @method ProvincesQuery groupByProvinceDefId() Group by the province_def_id column
 * @method ProvincesQuery groupByActive() Group by the active column
 *
 * @method ProvincesQuery leftJoin($relation) Adds a LEFT JOIN clause to the query
 * @method ProvincesQuery rightJoin($relation) Adds a RIGHT JOIN clause to the query
 * @method ProvincesQuery innerJoin($relation) Adds a INNER JOIN clause to the query
 *
 * @method ProvincesQuery leftJoinProvinceDefs($relationAlias = null) Adds a LEFT JOIN clause to the query using the ProvinceDefs relation
 * @method ProvincesQuery rightJoinProvinceDefs($relationAlias = null) Adds a RIGHT JOIN clause to the query using the ProvinceDefs relation
 * @method ProvincesQuery innerJoinProvinceDefs($relationAlias = null) Adds a INNER JOIN clause to the query using the ProvinceDefs relation
 *
 * @method ProvincesQuery leftJoinPlayers($relationAlias = null) Adds a LEFT JOIN clause to the query using the Players relation
 * @method ProvincesQuery rightJoinPlayers($relationAlias = null) Adds a RIGHT JOIN clause to the query using the Players relation
 * @method ProvincesQuery innerJoinPlayers($relationAlias = null) Adds a INNER JOIN clause to the query using the Players relation
 *
 * @method ProvincesQuery leftJoinArmy($relationAlias = null) Adds a LEFT JOIN clause to the query using the Army relation
 * @method ProvincesQuery rightJoinArmy($relationAlias = null) Adds a RIGHT JOIN clause to the query using the Army relation
 * @method ProvincesQuery innerJoinArmy($relationAlias = null) Adds a INNER JOIN clause to the query using the Army relation
 *
 * @method ProvincesQuery leftJoinInfrastructures($relationAlias = null) Adds a LEFT JOIN clause to the query using the Infrastructures relation
 * @method ProvincesQuery rightJoinInfrastructures($relationAlias = null) Adds a RIGHT JOIN clause to the query using the Infrastructures relation
 * @method ProvincesQuery innerJoinInfrastructures($relationAlias = null) Adds a INNER JOIN clause to the query using the Infrastructures relation
 *
 * @method ProvincesQuery leftJoinMaterials($relationAlias = null) Adds a LEFT JOIN clause to the query using the Materials relation
 * @method ProvincesQuery rightJoinMaterials($relationAlias = null) Adds a RIGHT JOIN clause to the query using the Materials relation
 * @method ProvincesQuery innerJoinMaterials($relationAlias = null) Adds a INNER JOIN clause to the query using the Materials relation
 *
 * @method ProvincesQuery leftJoinProvinceHistories($relationAlias = null) Adds a LEFT JOIN clause to the query using the ProvinceHistories relation
 * @method ProvincesQuery rightJoinProvinceHistories($relationAlias = null) Adds a RIGHT JOIN clause to the query using the ProvinceHistories relation
 * @method ProvincesQuery innerJoinProvinceHistories($relationAlias = null) Adds a INNER JOIN clause to the query using the ProvinceHistories relation
 *
 * @method ProvincesQuery leftJoinWarRelatedByAttackerProvinceId($relationAlias = null) Adds a LEFT JOIN clause to the query using the WarRelatedByAttackerProvinceId relation
 * @method ProvincesQuery rightJoinWarRelatedByAttackerProvinceId($relationAlias = null) Adds a RIGHT JOIN clause to the query using the WarRelatedByAttackerProvinceId relation
 * @method ProvincesQuery innerJoinWarRelatedByAttackerProvinceId($relationAlias = null) Adds a INNER JOIN clause to the query using the WarRelatedByAttackerProvinceId relation
 *
 * @method ProvincesQuery leftJoinWarRelatedByOpponentProvinceId($relationAlias = null) Adds a LEFT JOIN clause to the query using the WarRelatedByOpponentProvinceId relation
 * @method ProvincesQuery rightJoinWarRelatedByOpponentProvinceId($relationAlias = null) Adds a RIGHT JOIN clause to the query using the WarRelatedByOpponentProvinceId relation
 * @method ProvincesQuery innerJoinWarRelatedByOpponentProvinceId($relationAlias = null) Adds a INNER JOIN clause to the query using the WarRelatedByOpponentProvinceId relation
 *
 * @method Provinces findOne(PropelPDO $con = null) Return the first Provinces matching the query
 * @method Provinces findOneOrCreate(PropelPDO $con = null) Return the first Provinces matching the query, or a new Provinces object populated from the query conditions when no match is found
 *
 * @method Provinces findOneByGameId(int $game_id) Return the first Provinces filtered by the game_id column
 * @method Provinces findOneByPlayerId(int $player_id) Return the first Provinces filtered by the player_id column
 * @method Provinces findOneByProvinceDefId(int $province_def_id) Return the first Provinces filtered by the province_def_id column
 * @method Provinces findOneByActive(int $active) Return the first Provinces filtered by the active column
 *
 * @method array findById(int $id) Return Provinces objects filtered by the id column
 * @method array findByGameId(int $game_id) Return Provinces objects filtered by the game_id column
 * @method array findByPlayerId(int $player_id) Return Provinces objects filtered by the player_id column
 * @method array findByProvinceDefId(int $province_def_id) Return Provinces objects filtered by the province_def_id column
 * @method array findByActive(int $active) Return Provinces objects filtered by the active column
 *
 * @package    propel.generator.nawragon.om
 */
abstract class BaseProvincesQuery extends ModelCriteria
{
    /**
     * Initializes internal state of BaseProvincesQuery object.
     *
     * @param     string $dbName The dabase name
     * @param     string $modelName The phpName of a model, e.g. 'Book'
     * @param     string $modelAlias The alias for the model in this query, e.g. 'b'
     */
    public function __construct($dbName = 'nawragon', $modelName = 'Provinces', $modelAlias = null)
    {
        parent::__construct($dbName, $modelName, $modelAlias);
    }

    /**
     * Returns a new ProvincesQuery object.
     *
     * @param     string $modelAlias The alias of a model in the query
     * @param   ProvincesQuery|Criteria $criteria Optional Criteria to build the query from
     *
     * @return ProvincesQuery
     */
    public static function create($modelAlias = null, $criteria = null)
    {
        if ($criteria instanceof ProvincesQuery) {
            return $criteria;
        }
        $query = new ProvincesQuery();
        if (null !== $modelAlias) {
            $query->setModelAlias($modelAlias);
        }
        if ($criteria instanceof Criteria) {
            $query->mergeWith($criteria);
        }

        return $query;
    }

    /**
     * Find object by primary key.
     * Propel uses the instance pool to skip the database if the object exists.
     * Go fast if the query is untouched.
     *
     * <code>
     * $obj  = $c->findPk(12, $con);
     * </code>
     *
     * @param mixed $key Primary key to use for the query
     * @param     PropelPDO $con an optional connection object
     *
     * @return   Provinces|Provinces[]|mixed the result, formatted by the current formatter
     */
    public function findPk($key, $con = null)
    {
        if ($key === null) {
            return null;
        }
        if ((null !== ($obj = ProvincesPeer::getInstanceFromPool((string) $key))) && !$this->formatter) {
            // the object is alredy in the instance pool
            return $obj;
        }
        if ($con === null) {
            $con = Propel::getConnection(ProvincesPeer::DATABASE_NAME, Propel::CONNECTION_READ);
        }
        $this->basePreSelect($con);
        if ($this->formatter || $this->modelAlias || $this->with || $this->select
         || $this->selectColumns || $this->asColumns || $this->selectModifiers
         || $this->map || $this->having || $this->joins) {
            return $this->findPkComplex($key, $con);
        } else {
            return $this->findPkSimple($key, $con);
        }
    }

    /**
     * Alias of findPk to use instance pooling
     *
     * @param     mixed $key Primary key to use for the query
     * @param     PropelPDO $con A connection object
     *
     * @return                 Provinces A model object, or null if the key is not found
     * @throws PropelException
     */
     public function findOneById($key, $con = null)
     {
        return $this->findPk($key, $con);
     }

    /**
     * Find object by primary key using raw SQL to go fast.
     * Bypass doSelect() and the object formatter by using generated code.
     *
     * @param     mixed $key Primary key to use for the query
     * @param     PropelPDO $con A connection object
     *
     * @return                 Provinces A model object, or null if the key is not found
     * @throws PropelException
     */
    protected function findPkSimple($key, $con)
    {
        $sql = 'SELECT `id`, `game_id`, `player_id`, `province_def_id`, `active` FROM `provinces` WHERE `id` = :p0';
        try {
            $stmt = $con->prepare($sql);
            $stmt->bindValue(':p0', $key, PDO::PARAM_INT);
            $stmt->execute();
        } catch (Exception $e) {
            Propel::log($e->getMessage(), Propel::LOG_ERR);
            throw new PropelException(sprintf('Unable to execute SELECT statement [%s]', $sql), $e);
        }
        $obj = null;
        if ($row = $stmt->fetch(PDO::FETCH_NUM)) {
            $obj = new Provinces();
            $obj->hydrate($row);
            ProvincesPeer::addInstanceToPool($obj, (string) $key);
        }
        $stmt->closeCursor();

        return $obj;
    }

    /**
     * Find object by primary key.
     *
     * @param     mixed $key Primary key to use for the query
     * @param     PropelPDO $con A connection object
     *
     * @return Provinces|Provinces[]|mixed the result, formatted by the current formatter
     */
    protected function findPkComplex($key, $con)
    {
        // As the query uses a PK condition, no limit(1) is necessary.
        $criteria = $this->isKeepQuery() ? clone $this : $this;
        $stmt = $criteria
            ->filterByPrimaryKey($key)
            ->doSelect($con);

        return $criteria->getFormatter()->init($criteria)->formatOne($stmt);
    }

    /**
     * Find objects by primary key
     * <code>
     * $objs = $c->findPks(array(12, 56, 832), $con);
     * </code>
     * @param     array $keys Primary keys to use for the query
     * @param     PropelPDO $con an optional connection object
     *
     * @return PropelObjectCollection|Provinces[]|mixed the list of results, formatted by the current formatter
     */
    public function findPks($keys, $con = null)
    {
        if ($con === null) {
            $con = Propel::getConnection($this->getDbName(), Propel::CONNECTION_READ);
        }
        $this->basePreSelect($con);
        $criteria = $this->isKeepQuery() ? clone $this : $this;
        $stmt = $criteria
            ->filterByPrimaryKeys($keys)
            ->doSelect($con);

        return $criteria->getFormatter()->init($criteria)->format($stmt);
    }

    /**
     * Filter the query by primary key
     *
     * @param     mixed $key Primary key to use for the query
     *
     * @return ProvincesQuery The current query, for fluid interface
     */
    public function filterByPrimaryKey($key)
    {

        return $this->addUsingAlias(ProvincesPeer::ID, $key, Criteria::EQUAL);
    }

    /**
     * Filter the query by a list of primary keys
     *
     * @param     array $keys The list of primary key to use for the query
     *
     * @return ProvincesQuery The current query, for fluid interface
     */
    public function filterByPrimaryKeys($keys)
    {

        return $this->addUsingAlias(ProvincesPeer::ID, $keys, Criteria::IN);
    }

    /**
     * Filter the query on the id column
     *
     * Example usage:
     * <code>
     * $query->filterById(1234); // WHERE id = 1234
     * $query->filterById(array(12, 34)); // WHERE id IN (12, 34)
     * $query->filterById(array('min' => 12)); // WHERE id >= 12
     * $query->filterById(array('max' => 12)); // WHERE id <= 12
     * </code>
     *
     * @param     mixed $id The value to use as filter.
     *              Use scalar values for equality.
     *              Use array values for in_array() equivalent.
     *              Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
     *
     * @return ProvincesQuery The current query, for fluid interface
     */
    public function filterById($id = null, $comparison = null)
    {
        if (is_array($id)) {
            $useMinMax = false;
            if (isset($id['min'])) {
                $this->addUsingAlias(ProvincesPeer::ID, $id['min'], Criteria::GREATER_EQUAL);
                $useMinMax = true;
            }
            if (isset($id['max'])) {
                $this->addUsingAlias(ProvincesPeer::ID, $id['max'], Criteria::LESS_EQUAL);
                $useMinMax = true;
            }
            if ($useMinMax) {
                return $this;
            }
            if (null === $comparison) {
                $comparison = Criteria::IN;
            }
        }

        return $this->addUsingAlias(ProvincesPeer::ID, $id, $comparison);
    }

    /**
     * Filter the query on the game_id column
     *
     * Example usage:
     * <code>
     * $query->filterByGameId(1234); // WHERE game_id = 1234
     * $query->filterByGameId(array(12, 34)); // WHERE game_id IN (12, 34)
     * $query->filterByGameId(array('min' => 12)); // WHERE game_id >= 12
     * $query->filterByGameId(array('max' => 12)); // WHERE game_id <= 12
     * </code>
     *
     * @see       filterByPlayers()
     *
     * @param     mixed $gameId The value to use as filter.
     *              Use scalar values for equality.
     *              Use array values for in_array() equivalent.
     *              Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
     *
     * @return ProvincesQuery The current query, for fluid interface
     */
    public function filterByGameId($gameId = null, $comparison = null)
    {
        if (is_array($gameId)) {
            $useMinMax = false;
            if (isset($gameId['min'])) {
                $this->addUsingAlias(ProvincesPeer::GAME_ID, $gameId['min'], Criteria::GREATER_EQUAL);
                $useMinMax = true;
            }
            if (isset($gameId['max'])) {
                $this->addUsingAlias(ProvincesPeer::GAME_ID, $gameId['max'], Criteria::LESS_EQUAL);
                $useMinMax = true;
            }
            if ($useMinMax) {
                return $this;
            }
            if (null === $comparison) {
                $comparison = Criteria::IN;
            }
        }

        return $this->addUsingAlias(ProvincesPeer::GAME_ID, $gameId, $comparison);
    }

    /**
     * Filter the query on the player_id column
     *
     * Example usage:
     * <code>
     * $query->filterByPlayerId(1234); // WHERE player_id = 1234
     * $query->filterByPlayerId(array(12, 34)); // WHERE player_id IN (12, 34)
     * $query->filterByPlayerId(array('min' => 12)); // WHERE player_id >= 12
     * $query->filterByPlayerId(array('max' => 12)); // WHERE player_id <= 12
     * </code>
     *
     * @see       filterByPlayers()
     *
     * @param     mixed $playerId The value to use as filter.
     *              Use scalar values for equality.
     *              Use array values for in_array() equivalent.
     *              Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
     *
     * @return ProvincesQuery The current query, for fluid interface
     */
    public function filterByPlayerId($playerId = null, $comparison = null)
    {
        if (is_array($playerId)) {
            $useMinMax = false;
            if (isset($playerId['min'])) {
                $this->addUsingAlias(ProvincesPeer::PLAYER_ID, $playerId['min'], Criteria::GREATER_EQUAL);
                $useMinMax = true;
            }
            if (isset($playerId['max'])) {
                $this->addUsingAlias(ProvincesPeer::PLAYER_ID, $playerId['max'], Criteria::LESS_EQUAL);
                $useMinMax = true;
            }
            if ($useMinMax) {
                return $this;
            }
            if (null === $comparison) {
                $comparison = Criteria::IN;
            }
        }

        return $this->addUsingAlias(ProvincesPeer::PLAYER_ID, $playerId, $comparison);
    }

    /**
     * Filter the query on the province_def_id column
     *
     * Example usage:
     * <code>
     * $query->filterByProvinceDefId(1234); // WHERE province_def_id = 1234
     * $query->filterByProvinceDefId(array(12, 34)); // WHERE province_def_id IN (12, 34)
     * $query->filterByProvinceDefId(array('min' => 12)); // WHERE province_def_id >= 12
     * $query->filterByProvinceDefId(array('max' => 12)); // WHERE province_def_id <= 12
     * </code>
     *
     * @see       filterByProvinceDefs()
     *
     * @param     mixed $provinceDefId The value to use as filter.
     *              Use scalar values for equality.
     *              Use array values for in_array() equivalent.
     *              Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
     *
     * @return ProvincesQuery The current query, for fluid interface
     */
    public function filterByProvinceDefId($provinceDefId = null, $comparison = null)
    {
        if (is_array($provinceDefId)) {
            $useMinMax = false;
            if (isset($provinceDefId['min'])) {
                $this->addUsingAlias(ProvincesPeer::PROVINCE_DEF_ID, $provinceDefId['min'], Criteria::GREATER_EQUAL);
                $useMinMax = true;
            }
            if (isset($provinceDefId['max'])) {
                $this->addUsingAlias(ProvincesPeer::PROVINCE_DEF_ID, $provinceDefId['max'], Criteria::LESS_EQUAL);
                $useMinMax = true;
            }
            if ($useMinMax) {
                return $this;
            }
            if (null === $comparison) {
                $comparison = Criteria::IN;
            }
        }

        return $this->addUsingAlias(ProvincesPeer::PROVINCE_DEF_ID, $provinceDefId, $comparison);
    }

    /**
     * Filter the query on the active column
     *
     * Example usage:
     * <code>
     * $query->filterByActive(1234); // WHERE active = 1234
     * $query->filterByActive(array(12, 34)); // WHERE active IN (12, 34)
     * $query->filterByActive(array('min' => 12)); // WHERE active >= 12
     * $query->filterByActive(array('max' => 12)); // WHERE active <= 12
     * </code>
     *
     * @param     mixed $active The value to use as filter.
     *              Use scalar values for equality.
     *              Use array values for in_array() equivalent.
     *              Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
     *
     * @return ProvincesQuery The current query, for fluid interface
     */
    public function filterByActive($active = null, $comparison = null)
    {
        if (is_array($active)) {
            $useMinMax = false;
            if (isset($active['min'])) {
                $this->addUsingAlias(ProvincesPeer::ACTIVE, $active['min'], Criteria::GREATER_EQUAL);
                $useMinMax = true;
            }
            if (isset($active['max'])) {
                $this->addUsingAlias(ProvincesPeer::ACTIVE, $active['max'], Criteria::LESS_EQUAL);
                $useMinMax = true;
            }
            if ($useMinMax) {
                return $this;
            }
            if (null === $comparison) {
                $comparison = Criteria::IN;
            }
        }

        return $this->addUsingAlias(ProvincesPeer::ACTIVE, $active, $comparison);
    }

    /**
     * Filter the query by a related ProvinceDefs object
     *
     * @param   ProvinceDefs|PropelObjectCollection $provinceDefs The related object(s) to use as filter
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
     *
     * @return                 ProvincesQuery The current query, for fluid interface
     * @throws PropelException - if the provided filter is invalid.
     */
    public function filterByProvinceDefs($provinceDefs, $comparison = null)
    {
        if ($provinceDefs instanceof ProvinceDefs) {
            return $this
                ->addUsingAlias(ProvincesPeer::PROVINCE_DEF_ID, $provinceDefs->getId(), $comparison);
        } elseif ($provinceDefs instanceof PropelObjectCollection) {
            if (null === $comparison) {
                $comparison = Criteria::IN;
            }

            return $this
                ->addUsingAlias(ProvincesPeer::PROVINCE_DEF_ID, $provinceDefs->toKeyValue('PrimaryKey', 'Id'), $comparison);
        } else {
            throw new PropelException('filterByProvinceDefs() only accepts arguments of type ProvinceDefs or PropelCollection');
        }
    }

    /**
     * Adds a JOIN clause to the query using the ProvinceDefs relation
     *
     * @param     string $relationAlias optional alias for the relation
     * @param     string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
     *
     * @return ProvincesQuery The current query, for fluid interface
     */
    public function joinProvinceDefs($relationAlias = null, $joinType = Criteria::INNER_JOIN)
    {
        $tableMap = $this->getTableMap();
        $relationMap = $tableMap->getRelation('ProvinceDefs');

        // create a ModelJoin object for this join
        $join = new ModelJoin();
        $join->setJoinType($joinType);
        $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias);
        if ($previousJoin = $this->getPreviousJoin()) {
            $join->setPreviousJoin($previousJoin);
        }

        // add the ModelJoin to the current object
        if ($relationAlias) {
            $this->addAlias($relationAlias, $relationMap->getRightTable()->getName());
            $this->addJoinObject($join, $relationAlias);
        } else {
            $this->addJoinObject($join, 'ProvinceDefs');
        }

        return $this;
    }

    /**
     * Use the ProvinceDefs relation ProvinceDefs object
     *
     * @see       useQuery()
     *
     * @param     string $relationAlias optional alias for the relation,
     *                                   to be used as main alias in the secondary query
     * @param     string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
     *
     * @return   ProvinceDefsQuery A secondary query class using the current class as primary query
     */
    public function useProvinceDefsQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN)
    {
        return $this
            ->joinProvinceDefs($relationAlias, $joinType)
            ->useQuery($relationAlias ? $relationAlias : 'ProvinceDefs', 'ProvinceDefsQuery');
    }

    /**
     * Filter the query by a related Players object
     *
     * @param   Players $players The related object to use as filter
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
     *
     * @return                 ProvincesQuery The current query, for fluid interface
     * @throws PropelException - if the provided filter is invalid.
     */
    public function filterByPlayers($players, $comparison = null)
    {
        if ($players instanceof Players) {
            return $this
                ->addUsingAlias(ProvincesPeer::PLAYER_ID, $players->getId(), $comparison)
                ->addUsingAlias(ProvincesPeer::GAME_ID, $players->getGameId(), $comparison);
        } else {
            throw new PropelException('filterByPlayers() only accepts arguments of type Players');
        }
    }

    /**
     * Adds a JOIN clause to the query using the Players relation
     *
     * @param     string $relationAlias optional alias for the relation
     * @param     string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
     *
     * @return ProvincesQuery The current query, for fluid interface
     */
    public function joinPlayers($relationAlias = null, $joinType = Criteria::INNER_JOIN)
    {
        $tableMap = $this->getTableMap();
        $relationMap = $tableMap->getRelation('Players');

        // create a ModelJoin object for this join
        $join = new ModelJoin();
        $join->setJoinType($joinType);
        $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias);
        if ($previousJoin = $this->getPreviousJoin()) {
            $join->setPreviousJoin($previousJoin);
        }

        // add the ModelJoin to the current object
        if ($relationAlias) {
            $this->addAlias($relationAlias, $relationMap->getRightTable()->getName());
            $this->addJoinObject($join, $relationAlias);
        } else {
            $this->addJoinObject($join, 'Players');
        }

        return $this;
    }

    /**
     * Use the Players relation Players object
     *
     * @see       useQuery()
     *
     * @param     string $relationAlias optional alias for the relation,
     *                                   to be used as main alias in the secondary query
     * @param     string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
     *
     * @return   PlayersQuery A secondary query class using the current class as primary query
     */
    public function usePlayersQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN)
    {
        return $this
            ->joinPlayers($relationAlias, $joinType)
            ->useQuery($relationAlias ? $relationAlias : 'Players', 'PlayersQuery');
    }

    /**
     * Filter the query by a related Army object
     *
     * @param   Army|PropelObjectCollection $army  the related object to use as filter
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
     *
     * @return                 ProvincesQuery The current query, for fluid interface
     * @throws PropelException - if the provided filter is invalid.
     */
    public function filterByArmy($army, $comparison = null)
    {
        if ($army instanceof Army) {
            return $this
                ->addUsingAlias(ProvincesPeer::ID, $army->getProvinceId(), $comparison);
        } elseif ($army instanceof PropelObjectCollection) {
            return $this
                ->useArmyQuery()
                ->filterByPrimaryKeys($army->getPrimaryKeys())
                ->endUse();
        } else {
            throw new PropelException('filterByArmy() only accepts arguments of type Army or PropelCollection');
        }
    }

    /**
     * Adds a JOIN clause to the query using the Army relation
     *
     * @param     string $relationAlias optional alias for the relation
     * @param     string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
     *
     * @return ProvincesQuery The current query, for fluid interface
     */
    public function joinArmy($relationAlias = null, $joinType = Criteria::INNER_JOIN)
    {
        $tableMap = $this->getTableMap();
        $relationMap = $tableMap->getRelation('Army');

        // create a ModelJoin object for this join
        $join = new ModelJoin();
        $join->setJoinType($joinType);
        $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias);
        if ($previousJoin = $this->getPreviousJoin()) {
            $join->setPreviousJoin($previousJoin);
        }

        // add the ModelJoin to the current object
        if ($relationAlias) {
            $this->addAlias($relationAlias, $relationMap->getRightTable()->getName());
            $this->addJoinObject($join, $relationAlias);
        } else {
            $this->addJoinObject($join, 'Army');
        }

        return $this;
    }

    /**
     * Use the Army relation Army object
     *
     * @see       useQuery()
     *
     * @param     string $relationAlias optional alias for the relation,
     *                                   to be used as main alias in the secondary query
     * @param     string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
     *
     * @return   ArmyQuery A secondary query class using the current class as primary query
     */
    public function useArmyQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN)
    {
        return $this
            ->joinArmy($relationAlias, $joinType)
            ->useQuery($relationAlias ? $relationAlias : 'Army', 'ArmyQuery');
    }

    /**
     * Filter the query by a related Infrastructures object
     *
     * @param   Infrastructures|PropelObjectCollection $infrastructures  the related object to use as filter
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
     *
     * @return                 ProvincesQuery The current query, for fluid interface
     * @throws PropelException - if the provided filter is invalid.
     */
    public function filterByInfrastructures($infrastructures, $comparison = null)
    {
        if ($infrastructures instanceof Infrastructures) {
            return $this
                ->addUsingAlias(ProvincesPeer::ID, $infrastructures->getProvinceId(), $comparison);
        } elseif ($infrastructures instanceof PropelObjectCollection) {
            return $this
                ->useInfrastructuresQuery()
                ->filterByPrimaryKeys($infrastructures->getPrimaryKeys())
                ->endUse();
        } else {
            throw new PropelException('filterByInfrastructures() only accepts arguments of type Infrastructures or PropelCollection');
        }
    }

    /**
     * Adds a JOIN clause to the query using the Infrastructures relation
     *
     * @param     string $relationAlias optional alias for the relation
     * @param     string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
     *
     * @return ProvincesQuery The current query, for fluid interface
     */
    public function joinInfrastructures($relationAlias = null, $joinType = Criteria::INNER_JOIN)
    {
        $tableMap = $this->getTableMap();
        $relationMap = $tableMap->getRelation('Infrastructures');

        // create a ModelJoin object for this join
        $join = new ModelJoin();
        $join->setJoinType($joinType);
        $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias);
        if ($previousJoin = $this->getPreviousJoin()) {
            $join->setPreviousJoin($previousJoin);
        }

        // add the ModelJoin to the current object
        if ($relationAlias) {
            $this->addAlias($relationAlias, $relationMap->getRightTable()->getName());
            $this->addJoinObject($join, $relationAlias);
        } else {
            $this->addJoinObject($join, 'Infrastructures');
        }

        return $this;
    }

    /**
     * Use the Infrastructures relation Infrastructures object
     *
     * @see       useQuery()
     *
     * @param     string $relationAlias optional alias for the relation,
     *                                   to be used as main alias in the secondary query
     * @param     string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
     *
     * @return   InfrastructuresQuery A secondary query class using the current class as primary query
     */
    public function useInfrastructuresQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN)
    {
        return $this
            ->joinInfrastructures($relationAlias, $joinType)
            ->useQuery($relationAlias ? $relationAlias : 'Infrastructures', 'InfrastructuresQuery');
    }

    /**
     * Filter the query by a related Materials object
     *
     * @param   Materials|PropelObjectCollection $materials  the related object to use as filter
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
     *
     * @return                 ProvincesQuery The current query, for fluid interface
     * @throws PropelException - if the provided filter is invalid.
     */
    public function filterByMaterials($materials, $comparison = null)
    {
        if ($materials instanceof Materials) {
            return $this
                ->addUsingAlias(ProvincesPeer::ID, $materials->getProvinceId(), $comparison);
        } elseif ($materials instanceof PropelObjectCollection) {
            return $this
                ->useMaterialsQuery()
                ->filterByPrimaryKeys($materials->getPrimaryKeys())
                ->endUse();
        } else {
            throw new PropelException('filterByMaterials() only accepts arguments of type Materials or PropelCollection');
        }
    }

    /**
     * Adds a JOIN clause to the query using the Materials relation
     *
     * @param     string $relationAlias optional alias for the relation
     * @param     string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
     *
     * @return ProvincesQuery The current query, for fluid interface
     */
    public function joinMaterials($relationAlias = null, $joinType = Criteria::INNER_JOIN)
    {
        $tableMap = $this->getTableMap();
        $relationMap = $tableMap->getRelation('Materials');

        // create a ModelJoin object for this join
        $join = new ModelJoin();
        $join->setJoinType($joinType);
        $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias);
        if ($previousJoin = $this->getPreviousJoin()) {
            $join->setPreviousJoin($previousJoin);
        }

        // add the ModelJoin to the current object
        if ($relationAlias) {
            $this->addAlias($relationAlias, $relationMap->getRightTable()->getName());
            $this->addJoinObject($join, $relationAlias);
        } else {
            $this->addJoinObject($join, 'Materials');
        }

        return $this;
    }

    /**
     * Use the Materials relation Materials object
     *
     * @see       useQuery()
     *
     * @param     string $relationAlias optional alias for the relation,
     *                                   to be used as main alias in the secondary query
     * @param     string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
     *
     * @return   MaterialsQuery A secondary query class using the current class as primary query
     */
    public function useMaterialsQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN)
    {
        return $this
            ->joinMaterials($relationAlias, $joinType)
            ->useQuery($relationAlias ? $relationAlias : 'Materials', 'MaterialsQuery');
    }

    /**
     * Filter the query by a related ProvinceHistories object
     *
     * @param   ProvinceHistories|PropelObjectCollection $provinceHistories  the related object to use as filter
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
     *
     * @return                 ProvincesQuery The current query, for fluid interface
     * @throws PropelException - if the provided filter is invalid.
     */
    public function filterByProvinceHistories($provinceHistories, $comparison = null)
    {
        if ($provinceHistories instanceof ProvinceHistories) {
            return $this
                ->addUsingAlias(ProvincesPeer::ID, $provinceHistories->getProvinceId(), $comparison);
        } elseif ($provinceHistories instanceof PropelObjectCollection) {
            return $this
                ->useProvinceHistoriesQuery()
                ->filterByPrimaryKeys($provinceHistories->getPrimaryKeys())
                ->endUse();
        } else {
            throw new PropelException('filterByProvinceHistories() only accepts arguments of type ProvinceHistories or PropelCollection');
        }
    }

    /**
     * Adds a JOIN clause to the query using the ProvinceHistories relation
     *
     * @param     string $relationAlias optional alias for the relation
     * @param     string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
     *
     * @return ProvincesQuery The current query, for fluid interface
     */
    public function joinProvinceHistories($relationAlias = null, $joinType = Criteria::INNER_JOIN)
    {
        $tableMap = $this->getTableMap();
        $relationMap = $tableMap->getRelation('ProvinceHistories');

        // create a ModelJoin object for this join
        $join = new ModelJoin();
        $join->setJoinType($joinType);
        $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias);
        if ($previousJoin = $this->getPreviousJoin()) {
            $join->setPreviousJoin($previousJoin);
        }

        // add the ModelJoin to the current object
        if ($relationAlias) {
            $this->addAlias($relationAlias, $relationMap->getRightTable()->getName());
            $this->addJoinObject($join, $relationAlias);
        } else {
            $this->addJoinObject($join, 'ProvinceHistories');
        }

        return $this;
    }

    /**
     * Use the ProvinceHistories relation ProvinceHistories object
     *
     * @see       useQuery()
     *
     * @param     string $relationAlias optional alias for the relation,
     *                                   to be used as main alias in the secondary query
     * @param     string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
     *
     * @return   ProvinceHistoriesQuery A secondary query class using the current class as primary query
     */
    public function useProvinceHistoriesQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN)
    {
        return $this
            ->joinProvinceHistories($relationAlias, $joinType)
            ->useQuery($relationAlias ? $relationAlias : 'ProvinceHistories', 'ProvinceHistoriesQuery');
    }

    /**
     * Filter the query by a related War object
     *
     * @param   War|PropelObjectCollection $war  the related object to use as filter
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
     *
     * @return                 ProvincesQuery The current query, for fluid interface
     * @throws PropelException - if the provided filter is invalid.
     */
    public function filterByWarRelatedByAttackerProvinceId($war, $comparison = null)
    {
        if ($war instanceof War) {
            return $this
                ->addUsingAlias(ProvincesPeer::ID, $war->getAttackerProvinceId(), $comparison);
        } elseif ($war instanceof PropelObjectCollection) {
            return $this
                ->useWarRelatedByAttackerProvinceIdQuery()
                ->filterByPrimaryKeys($war->getPrimaryKeys())
                ->endUse();
        } else {
            throw new PropelException('filterByWarRelatedByAttackerProvinceId() only accepts arguments of type War or PropelCollection');
        }
    }

    /**
     * Adds a JOIN clause to the query using the WarRelatedByAttackerProvinceId relation
     *
     * @param     string $relationAlias optional alias for the relation
     * @param     string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
     *
     * @return ProvincesQuery The current query, for fluid interface
     */
    public function joinWarRelatedByAttackerProvinceId($relationAlias = null, $joinType = Criteria::INNER_JOIN)
    {
        $tableMap = $this->getTableMap();
        $relationMap = $tableMap->getRelation('WarRelatedByAttackerProvinceId');

        // create a ModelJoin object for this join
        $join = new ModelJoin();
        $join->setJoinType($joinType);
        $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias);
        if ($previousJoin = $this->getPreviousJoin()) {
            $join->setPreviousJoin($previousJoin);
        }

        // add the ModelJoin to the current object
        if ($relationAlias) {
            $this->addAlias($relationAlias, $relationMap->getRightTable()->getName());
            $this->addJoinObject($join, $relationAlias);
        } else {
            $this->addJoinObject($join, 'WarRelatedByAttackerProvinceId');
        }

        return $this;
    }

    /**
     * Use the WarRelatedByAttackerProvinceId relation War object
     *
     * @see       useQuery()
     *
     * @param     string $relationAlias optional alias for the relation,
     *                                   to be used as main alias in the secondary query
     * @param     string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
     *
     * @return   WarQuery A secondary query class using the current class as primary query
     */
    public function useWarRelatedByAttackerProvinceIdQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN)
    {
        return $this
            ->joinWarRelatedByAttackerProvinceId($relationAlias, $joinType)
            ->useQuery($relationAlias ? $relationAlias : 'WarRelatedByAttackerProvinceId', 'WarQuery');
    }

    /**
     * Filter the query by a related War object
     *
     * @param   War|PropelObjectCollection $war  the related object to use as filter
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
     *
     * @return                 ProvincesQuery The current query, for fluid interface
     * @throws PropelException - if the provided filter is invalid.
     */
    public function filterByWarRelatedByOpponentProvinceId($war, $comparison = null)
    {
        if ($war instanceof War) {
            return $this
                ->addUsingAlias(ProvincesPeer::ID, $war->getOpponentProvinceId(), $comparison);
        } elseif ($war instanceof PropelObjectCollection) {
            return $this
                ->useWarRelatedByOpponentProvinceIdQuery()
                ->filterByPrimaryKeys($war->getPrimaryKeys())
                ->endUse();
        } else {
            throw new PropelException('filterByWarRelatedByOpponentProvinceId() only accepts arguments of type War or PropelCollection');
        }
    }

    /**
     * Adds a JOIN clause to the query using the WarRelatedByOpponentProvinceId relation
     *
     * @param     string $relationAlias optional alias for the relation
     * @param     string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
     *
     * @return ProvincesQuery The current query, for fluid interface
     */
    public function joinWarRelatedByOpponentProvinceId($relationAlias = null, $joinType = Criteria::INNER_JOIN)
    {
        $tableMap = $this->getTableMap();
        $relationMap = $tableMap->getRelation('WarRelatedByOpponentProvinceId');

        // create a ModelJoin object for this join
        $join = new ModelJoin();
        $join->setJoinType($joinType);
        $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias);
        if ($previousJoin = $this->getPreviousJoin()) {
            $join->setPreviousJoin($previousJoin);
        }

        // add the ModelJoin to the current object
        if ($relationAlias) {
            $this->addAlias($relationAlias, $relationMap->getRightTable()->getName());
            $this->addJoinObject($join, $relationAlias);
        } else {
            $this->addJoinObject($join, 'WarRelatedByOpponentProvinceId');
        }

        return $this;
    }

    /**
     * Use the WarRelatedByOpponentProvinceId relation War object
     *
     * @see       useQuery()
     *
     * @param     string $relationAlias optional alias for the relation,
     *                                   to be used as main alias in the secondary query
     * @param     string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
     *
     * @return   WarQuery A secondary query class using the current class as primary query
     */
    public function useWarRelatedByOpponentProvinceIdQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN)
    {
        return $this
            ->joinWarRelatedByOpponentProvinceId($relationAlias, $joinType)
            ->useQuery($relationAlias ? $relationAlias : 'WarRelatedByOpponentProvinceId', 'WarQuery');
    }

    /**
     * Exclude object from result
     *
     * @param   Provinces $provinces Object to remove from the list of results
     *
     * @return ProvincesQuery The current query, for fluid interface
     */
    public function prune($provinces = null)
    {
        if ($provinces) {
            $this->addUsingAlias(ProvincesPeer::ID, $provinces->getId(), Criteria::NOT_EQUAL);
        }

        return $this;
    }

}
